#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=2e5+100;
typedef int LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
char s[maxn];
LL dp[maxn][27],pos[27];
int main(void){
   	cin.tie(0);std::ios::sync_with_stdio(false);
	LL m,n;cin>>m>>n;
	fill(pos,pos+26,n+1);

	for(int i=1;i<=n;i++) cin>>s[i];

    for(int i=0;i<=18;i++) dp[n+1][i]=n+1;

    for(int i=n;i>=1;i--){
        for(int j=0;j<m;j++){
            dp[i][0]=max(dp[i][0],pos[j]);
        }
        pos[s[i]-'a']=i;
    }

    for(int j=0;j<m;j++) dp[0][0]=max(dp[0][0],pos[j]);

    for(int i=n;i>=0;i--){
        for(int j=1;j<=18;j++){
            dp[i][j]=dp[ dp[i][j-1] ] [j-1];
        }
    }

    LL q;cin>>q;
    while(q--){
        LL l,r;cin>>l>>r;
        l--;
        LL ans=0;
        for(int j=18;j>=0;j--){
            if(dp[l][j]<=r){
                l=dp[l][j];
                ans+=1LL<<j;
            }
        }
        ans++;
        cout<<ans<<endl;
    }
   	return 0;
}
